package cn.edu.tzc.controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
/**
 * 统一异常处理
 */
@ControllerAdvice   //  控制器增强
public class GlobalExceptionHandleController {
    @ExceptionHandler(value=Exception.class)  // Spring 全局异常处理注解，用于捕捉和处理控制器中抛出的异常
    public String exceptionHandler(Exception e, Model model) {
        String message = "";
        if (e instanceof NoLoginException) {
            message = "noLogin";
        } else {
            message =  "noError";
        }
        model.addAttribute("mymessage",message);
        return "error";
    }
}

